package org.yangspring.samples.mvc.CtrlOracle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yangspring.samples.mvc.domainOracle.Customers;
import org.yangspring.samples.mvc.domainOracle.Inventories;
import org.yangspring.samples.mvc.domainOracle.ProductDesc;
import org.yangspring.samples.mvc.domainOracle.ProductInfo;
import org.yangspring.samples.mvc.serviceOracle.CustomersService;
import org.yangspring.samples.mvc.serviceOracle.InventoriesService;
import org.yangspring.samples.mvc.serviceOracle.ProductDescService;
import org.yangspring.samples.mvc.serviceOracle.ProductInfoService;

import java.util.List;

import static java.lang.System.out;

/**
 * Created by whyang on 2017/06/22.
 */


@Controller
@RequestMapping("/oracle/oe")
public class OracleOECtrl {

    private static final Logger logger = LoggerFactory.getLogger(OracleOECtrl.class);

    @Autowired
//    @Resource(name = "customersService")
    private CustomersService customersService;

    @Autowired
//    @Resource(name = "prodInfoService")
    private ProductInfoService prodInfoService;

    @Autowired
//    @Resource(name = "prodDescService")
    private ProductDescService prodDescService;

    @Autowired
//    @Resource(name = "inventoryService")
    private InventoriesService inventoryService;

    @RequestMapping(value = {"/customer", "/customer/list"})
    public String customerList(Model model){

        logger.warn("\nOracle OE.CUSTOMERS Controller\n");

        model.addAttribute("customer001", new Customers());
        List<Customers> customers = this.customersService.listCustomer();
        logger.warn("\nlistCustomer017 Quantity:\t" + customers.size() + "\n");
        model.addAttribute("listCustomer017", customers);
        return "listCustomer";

    }

    @RequestMapping(value = {"/prodInfo", "/prodInfo/list"})
    public String prodInfoList(Model model){

        logger.warn("\nOracle OE.PRODUCT_INFORMATION Controller\n");

        model.addAttribute("prodInfo001", new ProductInfo());
        List<ProductInfo> prodInfos = this.prodInfoService.listProdInfo();
        logger.warn("\nlistProdInfo017 Quantity:\t" + prodInfos.size() + "\n");
        model.addAttribute("listProdInfo017", prodInfos);
        return "listprodInfos";

    }

    @RequestMapping(value = {"/prodDesc", "/prodDesc/list"})
    public String prodDescList(Model model){

        logger.warn("\nOracle OE.PRODUCT_DESCRIPTIONS Controller\n");

        model.addAttribute("prodDesc001", new ProductInfo());
        List<ProductDesc> prodDescs = this.prodDescService.listProdDesc();
        logger.warn("\nlistProdDesc017 Quantity:\t" + prodDescs.size() + "\n");
        model.addAttribute("listProdDesc017", prodDescs);
        return "listprodDescs";

    }

    @RequestMapping(value = {"/inventory", "/inventory/list"})
    public String prodInventoryList(Model model){

        logger.warn("\nOracle OE.INVENTORIES Controller\n");

        model.addAttribute("inventory001", new Inventories());
        List<Inventories> inventories = this.inventoryService.listInventory();
        logger.warn("\nlistinventory017 Quantity:\t" + inventories.size() + "\n");
        model.addAttribute("listinventory017", inventories);
        return "listinventories";

    }

}
